package com.liujit.upms.controller;

import com.liujit.upms.domain.model.SysOauthClient;
import com.liujit.upms.domain.params.SysOauthClientParams;
import com.liujit.upms.domain.query.SysOauthClientQuery;
import com.liujit.upms.domain.result.SysOauthClientResult;
import com.liujit.upms.service.SysOauthClientService;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 系统认证客户端管理接口
 * @Author liujun
 * @Date 2021-07-02 15:00:06
 */
@RequiredArgsConstructor
@Api(tags = "系统认证客户端管理接口")
@RestController
@RequestMapping("/sys/oauth/client")
public class SysOauthClientController {

    private final SysOauthClientService sysOauthClientService;

    @ApiOperation(value = "分页查询", notes = "根据系统认证客户端分页查询条件，分页查询系统认证客户端列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统认证客户端分页查询条件", dataType = "SysOauthClientQuery", dataTypeClass = SysOauthClientQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<SysOauthClientResult> getPage(SysOauthClientQuery query) {
        return sysOauthClientService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据系统认证客户端添加请求参数，添加系统认证客户端")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统认证客户端添加请求参数", dataType = "SysOauthClientParams", dataTypeClass = SysOauthClientParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) SysOauthClientParams params) {
        return sysOauthClientService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据系统认证客户端修改请求参数，修改系统认证客户端")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统认证客户端修改请求参数", dataType = "SysOauthClientParams", dataTypeClass = SysOauthClientParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) SysOauthClientParams params) {
        return sysOauthClientService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据系统认证客户端id，查询系统认证客户端")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统认证客户端id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public SysOauthClientResult get(Long id) {
        return sysOauthClientService.get(id);
    }

    @ApiOperation(value = "删除", notes = "根据系统认证客户端删除请求参数，删除系统认证客户端")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统认证客户端删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return sysOauthClientService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据系统认证客户端启用请求参数，启用系统认证客户端")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统认证客户端启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return sysOauthClientService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据系统认证客户端禁用请求参数，禁用系统认证客户端")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统认证客户端禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return sysOauthClientService.disabled(params);
    }

    @ApiOperation(value = "根据客户端唯一标识查询条数", notes = "根据系统认证客户端唯一标识查询系统认证客户端条数")
    @ApiImplicitParams({ @ApiImplicitParam(name = "clientId", value = "系统认证客户端唯一标识", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getCountByClientId")
    public Integer getCountByClientId(String clientId) {
        return sysOauthClientService.getCountByClientId(clientId);
    }

    @ApiOperation(value = "根据客户端唯一标识查询", notes = "根据系统认证客户端唯一标识查询系统认证客户端")
    @ApiImplicitParams({ @ApiImplicitParam(name = "clientId", value = "系统认证客户端唯一标识", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getByClientId")
    public SysOauthClient getByClientId(String clientId) {
        return sysOauthClientService.getByClientId(clientId);
    }
}
